package com.hksj.Intelligentmanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hksj.Intelligentmanagement.common.Rest;
import com.hksj.Intelligentmanagement.dto.MusicQuery;
import com.hksj.Intelligentmanagement.entity.Music;
import com.hksj.Intelligentmanagement.service.MusicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@Api(tags = "music-歌曲信息表")
@RestController
@RequestMapping("/api/music")
public class MusicController {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	public MusicService musicService;

	@ApiOperation(value = "上传歌曲")
	@PostMapping("/uploadMusic")
	public Rest uploadMusic(Long folderId, MultipartFile[] multipartFile) {
		musicService.uploadMusic(folderId,multipartFile);
		return Rest.ok();
	}

	@DeleteMapping("/deleteMusic/{id}")
	@ApiOperation(value = "删除歌曲信息表")
	public Rest deleteMusic(@PathVariable Long id){
		musicService.deleteMusic(id);
		return Rest.ok();
	}

	@PostMapping("/pageMusic")
	@ApiOperation(value = "分页查询歌曲信息表",response = Music.class)
	public Rest<IPage<Music>> pageMusic(@RequestBody MusicQuery query){
    	IPage<Music> page = musicService.pageMusic(query);
		return Rest.ok(page);
	}

	@ApiOperation(value = "同步歌曲(全量同步)")
	@PostMapping("/syncMusic")
	public void syncMusic(HttpServletResponse response) {
		musicService.syncMusic(response);
	}
}